<template>
  <div class="page-container">
    <div>
      <div class="download-app" v-if="!isDiManagerApp">
        <a class="download-btn" target="_blank" :href="downloadAppUrl">
          <i class="el-icon-download"
             style="background-color: white; color: #5daf34; padding: 4px; border-radius: 14px"></i>
          <span style="font-size: 18px; font-weight: 500">下载DiManager</span>
        </a>
      </div>
      <div v-else style="text-align: center; font-size: 20px; padding-top: 200px">
        <div class="download-btn" @click="doDownloadApp">
          <i class="el-icon-download"
             style="background-color: white; color: #5daf34; padding: 4px; border-radius: 14px"></i>
          <span style="font-size: 18px; font-weight: 500">下载DiManager</span>
        </div>
      </div>
    </div>
    <div style="margin-top: 40px">
      <a class="download-btn" target="_blank" :href="extentionUrl" v-if="!isDiManagerApp">
        <i class="el-icon-menu"
           style="background-color: white; color: #5daf34; padding: 4px; border-radius: 14px;"></i>
        <span style="font-size: 14px; font-weight: 500">谷歌浏览器插件下载</span>
      </a>
    </div>
    <div class="copy-right" ref="copyRightRef">
      <div>黔ICP备2021002127号</div>
      <div style="margin-top: 4px; font-size: 8px"> © {{year}}
        <span style="padding-left: 8px"></span>
        <span>DiManager</span>
        <span style="padding-left: 8px"></span>{{siteHost}}
      </div>
    </div>
  </div>
</template>

<script>
import {AppVersion} from './model/AppVersion'
import {SiteHost} from '../utils/AppConstant'
import {openAppUrlOnBrowser} from '../utils/downloadImg'

export default {
  name: 'Apps',
  data () {
    return {
      aNum: 0,
      macAppV: new AppVersion(),
      year: (new Date()).getFullYear()
    }
  },
  computed: {
    isMacOS: function () {
      const macOsIdx = window.navigator.userAgent.indexOf('Mac OS X')
      const iPhoneOsIdx = window.navigator.userAgent.indexOf('iPhone')
      return macOsIdx > 0 && iPhoneOsIdx < 0
    },
    isDiManagerApp: function () {
      // DiManagerWebView_1000
      const idx = window.navigator.userAgent.indexOf('ManagerWebView_')
      return idx > 0
    },
    siteHost: function () {
      return SiteHost.replace('//', '').split(':')[1]
    },
    downloadAppUrl: function () {
      return window.location.origin + '/DiManager.dmg'
    },
    extentionUrl: function () {
      return window.origin + '/' + 'di-manager-extension.zip'
    }
  },
  created () {
  },
  mounted () {
    window.document.title = 'DiManager | 下载'

    const timerId = setTimeout(() => {
      clearTimeout(timerId)
      this.$refs.copyRightRef.style.display = 'block'
    }, 1000)
  },
  destroyed () {
    window.document.title = 'DiManager'
  },
  methods: {
    doDownloadApp () {
      openAppUrlOnBrowser(this.downloadAppUrl)
    }
  }
}
</script>

<style scoped>
  .page-container {
    text-align: center;
  }

  .download-app {
    font-size: 20px;
    padding-top: 280px;
  }

  .download-btn {
    background-color: #07c160;
    padding: 17px 37px;
    border-radius: 6px;
    color: white;
    font-size: 16px;
    text-transform: capitalize;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
  }

  .download-btn:hover {
    background-color: #067A2D;
  }

  .copy-right {
    position: absolute;
    bottom: 16px;
    font-size: 10px;
    color: darkgrey;
    text-align: center;
    right: 16px;
    left: 16px;
    display: none;
  }
</style>
